package com.bite.demo;

import com.bite.demo.model.userInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JSON {
    public static ObjectMapper objectMapper = new ObjectMapper();
    public static void main(String[] args) throws JsonProcessingException {
        userInfo userInfo = new userInfo();
        userInfo.setUserName("zhangsan");
        userInfo.setAge(21);
        userInfo.setPassword("123456");
        //对象转化json
        String s = objectMapper.writeValueAsString(userInfo);
        System.out.println(s);

        //json转化java
        String jsonstr = "{\"userName\":\"zhangsan\",\"password\":\"123456\",\"age\":21}";
        com.bite.demo.model.userInfo userInfo1 = objectMapper.readValue(jsonstr, userInfo.class);
        System.out.println(userInfo1);


    }
}
